<template>
  <div class="contaner">
    <Header></Header>
    <div class="block">
      <el-timeline class="main-container">
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <h4>
              <router-link :to="{path:`/blog/${blog.id}`}">
                <span style="font-size:18px" class="font-style">{{ blog.title }}</span>
              </router-link>
            </h4>
            <p>{{ blog.description }}</p>
          </el-card>
        </el-timeline-item>

      </el-timeline>

      <el-pagination class="mpage"
                     background
                     layout="prev, pager, next"
                     :current-page="currentPage"
                     :page-size="pageSize"
                     :total="total"
                     @current-change=page>
      </el-pagination>

    </div>

  </div>
</template>

<script>
import Header from "../components/Header";

export default {
  components: {
    Header
  },
  name: "Blogs",
  data() {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 5
    }
  },
  methods: {
    page(currentPage) {
      const _this = this
      _this.$axios.get("/blogs?currentPage=" + currentPage).then(res => {
        console.log(res)
        _this.blogs = res.data.data.records
        _this.currentPage = res.data.data.current
        _this.total = res.data.data.total
        _this.pageSize = res.data.data.size

      })
    }
  },
  created() {
    this.page(1)
  }
}
</script>

<style scoped>
.main-container {
  width: 80%;
  margin: 0 auto;
}

.font-style {
  color: darkgray;
}

a {
  text-decoration: none;
}

.block {
  margin: 0 auto;
}

.router-link-active {
  text-decoration: none;
}

.mpage {
  margin: 0 auto;
  text-align: center;
}
</style>
